package cn.zyq.ykb.controller.h5.task;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.task.TaskStep;
import cn.zyq.ykb.service.task.TaskStepService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务-步骤Controller
 *
 * @author SystemAuth
 * @date 2023-05-22
 */

@RestController(value = "H5TaskStepController")
@RequestMapping("/api/taskStep")
@Api(tags = "任务-步骤接口")
public class TaskStepController extends BaseController {

    @Autowired
    private TaskStepService taskStepService;

    /**
     * 查询任务-步骤列表
     */
    @ApiOperation(value = "列表", response = TaskStep.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.taskStepService.selectTaskStepList(pageParam);
    }

     /**
      * 导出任务-步骤列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "任务-步骤" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, TaskStep taskStep) {
         List<TaskStep> list = taskStepService.selectTaskStepList(taskStep);
         ExcelUtil<TaskStep> util = new ExcelUtil<TaskStep>(TaskStep. class);
         util.exportExcel(response, list, "任务-步骤数据");
     }

    /**
     * 获取任务-步骤详细信息
     */
    @ApiOperation(value = "详情", response = TaskStep.class)
    @GetMapping(value = "/{taskStepID}")
    public Object getInfo(@PathVariable("taskStepID") Integer taskStepID) {
        return this.taskStepService.selectTaskStepByTaskStepID(taskStepID);
    }
    /**
     * 获取任务-步骤详细信息
     */
    @ApiOperation(value = "详情", response = TaskStep.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.taskStepService.selectTaskStepByServiceID(serviceID);
    }

    /**
     * 新增任务-步骤
     */
    @ApiOperation(value = "新增")
    @Log(title = "任务-步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody TaskStep taskStep) {
        return this.taskStepService.insertTaskStep(taskStep);
    }

    /**
     * 修改任务-步骤
     */
    @ApiOperation(value = "编辑")
    @Log(title = "任务-步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody TaskStep taskStep) {
        return this.taskStepService.updateTaskStep(taskStep);
    }

    /**
     * 删除任务-步骤
     */
    @ApiOperation(value = "删除")
    @Log(title = "任务-步骤", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskStepIDs}")
    public Object remove(@PathVariable Integer[] taskStepIDs) {
        return this.taskStepService.deleteTaskStepByTaskStepIDs(taskStepIDs);
    }
}
